using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class BulletMove : MonoBehaviour
{
    public float xSpeed,ySpeed;//子弹的水平速度和垂直速度
    void Start()//初始化随机子弹的速度
    {
        xSpeed=Random.Range(1f,10f);
        ySpeed=Random.Range(1f,10f);
    }
    void Update()
    {
        if (transform.position.x>2.5) xSpeed=Mathf.Min(xSpeed,-xSpeed);//如果子弹触碰到边界，则回弹
        if (transform.position.x<-7.9) xSpeed=Mathf.Max(xSpeed,-xSpeed);
        if (transform.position.y>4.5) ySpeed=Mathf.Min(ySpeed,-ySpeed);
        if (transform.position.y<-4.4) ySpeed=Mathf.Max(ySpeed,-ySpeed);
        transform.position+=new Vector3(xSpeed,ySpeed,0)*Time.deltaTime;
    }
}
